package com.ruoyi.web.controller.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.controller.service.ExcelImportInfoServiceImpl;
import com.ruoyi.web.controller.vo.ExcelQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * excel导入企业信息
 */
@Anonymous
@Validated
@RestController
@RequestMapping("/excelImportInfo")
public class ExcelImportInfoController extends BaseController {

    @Resource
    private ExcelImportInfoServiceImpl excelImportInfoService;

    // 上传文件
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) {
        excelImportInfoService.uploadFile(file);
        return AjaxResult.success();
    }

    // 下载文件
    @GetMapping("/download/{id}")
    public void fileDownload(@PathVariable Long id, HttpServletResponse response) {
        excelImportInfoService.download(id, response);
    }

    // excel文件列表查询
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ExcelQuery query) {
        return excelImportInfoService.queryList(query);
    }


    // 删除导入文件信息
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        excelImportInfoService.delete(id);
        return AjaxResult.success();
    }


}
